/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/10/18 18:39
@File     : user.go
@Project  : GoProject
@Desc     :
*/
package service

import (
	"GoProject/internal/model"
	"GoProject/internal/pkg/request"
	"GoProject/internal/repository"
	"context"
	"github.com/pkg/errors"
)

type UserService interface {
	Create(ctx context.Context, req *request.UserCreate) error
}

type userService struct {
	userRepo repository.UserRepository
	*Service
}

func NewUserService(service *Service, userRepo repository.UserRepository) UserService {
	return &userService{
		userRepo: userRepo,
		Service:  service,
	}
}

func (r *userService) Create(ctx context.Context, req *request.UserCreate) error {
	user := &model.User{
		Uid:      r.sid.GenId(),
		Username: req.Username,
		Nickname: req.Nickname,
		Password: req.Password,
		Email:    req.Email,
	}
	if err := r.userRepo.Create(ctx, user); err != nil {
		return errors.Wrap(err, "创建用户失败")
	}
	return nil
}
